package com.origin.utils.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.origin.utils.*
import kotlinx.android.synthetic.main.activity_file_utils.*
import java.io.File

class FileUtilsActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_file_utils)

    }

    fun write(view: View) {
        FileUtils.strToFile(msgEt.text.toString(), "1.txt")
    }

    fun move(view: View) {
        FileUtils.moveFile(File(PathUtils.filesPath + "/2.txt").absolutePath, File(PathUtils.filesPath + "/crash/1.txt").absolutePath)
    }

    fun rename(view: View) {
        FileUtils.renameFile(File(PathUtils.filesPath + "/1.txt"), "2.txt")
    }

    fun delete(view: View) {
        FileUtils.deleteFile(PathUtils.filesPath + "/crash/2022-05-30 17:01:58.txt")
    }

    fun read(view: View) {
        readText.text =
            FileUtils.readToFile(PathUtils.filesPath + "/1.txt")
    }

    fun writeAppend(view: View) {
        FileUtils.strToFileAppend(msgEt.text.toString(), "1.txt")
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
}